package com.guigu.qingcheng.controller;

import com.guigu.qingcheng.pojo.bussiness.TbAd;
import com.guigu.qingcheng.service.AdServiceFeign;
import com.guigu.qingcheng.service.GoodsServiceFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;

/**
 * 处理首页的所有请求
 */
@Controller
public class IndexController {
    @Autowired
    private AdServiceFeign adServiceFeign;

    @Autowired
    private GoodsServiceFeign goodsServiceFeign;

    @RequestMapping({"/index","/"})
    public String index (Model model) {
        List<TbAd> list = adServiceFeign.findByPosition("web_index_lb");
        model.addAttribute("lbt",list);
        List<Map> mapList = goodsServiceFeign.findCategoryList();
        model.addAttribute("categoryList", mapList);
        return "index";
    }

    @RequestMapping("register")
    public String register () {
        return "register";
    }

    @RequestMapping("cartre")
    public String cartre () {
        return "cart";
    }

    @RequestMapping("item")
    public String item () {
        return "item";
    }

    @RequestMapping("order")
    public String order () {
        return "order";
    }

    @RequestMapping("fail")
    public String fail () {
        return "fail";
    }


    @RequestMapping("pay")
    public String pay (Model model,String ordersn,String money) {
        DecimalFormat df=new DecimalFormat("0.00");
        model.addAttribute("ordersn",ordersn);
        model.addAttribute("money",df.format((float)Integer.parseInt(money)/100));
        return "pay";
    }

    @RequestMapping("success")
    public String success (Model model,String ordersn,String money) {
        DecimalFormat df=new DecimalFormat("0.00");
        model.addAttribute("ordersn",ordersn);
        model.addAttribute("money",df.format((float)Integer.parseInt(money)/100));
        return "order-success";
    }

    @RequestMapping("login")
    public String login () {
        return "login";
    }
}
